<?php
class picture_photo_row extends system_concept_row {

	protected $_image = null;
	/**
	 * @return resource_display
	 */
	public function getImage() {
		if($this->_image === null || ($this->_image->getHash() && $this->_image->getHash() != $this->get('hash'))) {
			$this->_image = new resource_display($this->get('hash'));
		}
		return $this->_image;
	}
	
	protected $_keyword = array();
	/**
	 *
	 * @return picture_photo_row
	 */
	public function setKeywords($keyword) {
		if(!$keyword) return $this;
		if(!is_array($keyword)) {
			$keyword = explode(';', trim((string) $keyword));
		}
		$k = array();
		foreach($keyword as $key) {
			$key = trim($key);
			if($key == '') continue;
			$k[] = $key;
		}
		
		$this->_keyword = $k;
		return $this;
	}
	public function getKeywords($lang) {
		$list = array();
		if($this->getId()) {
			$concept = new resource_keyword_concept($lang);
			foreach($concept->fetchAll(array('id IN (SELECT `keyword_id` FROM `picture_photo_keyword` WHERE `photo_id` = ?)' => $this->getId())) as $row) {
				$list[] = $row->getName();
			}
		}
		return array_merge($this->_keyword, $list);
	}
}
